package com.lixianhe.onlineexam.controller;


import com.lixianhe.onlineexam.pojo.Item;
import com.lixianhe.onlineexam.service.ItemService;
import com.lixianhe.onlineexam.util.ApiResultHandler;
import com.lixianhe.onlineexam.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;

    @PostMapping("item")
    public R item(@RequestBody Item item) {
        Integer changeNumber = item.getChangeNumber();
        Integer fillNumber = item.getFillNumber();
        Integer judgeNumber = item.getJudgeNumber();
        Integer paperId = item.getPaperId();
        String subject = item.getSubject();
        if (changeNumber == null && fillNumber == null && judgeNumber == null) return ApiResultHandler.buildApiResult(400, "题型数量不能全为空", null);
        else {
            itemService.cleanPaper(paperId);
            return itemService.randItem(item);
        }
    }
}
